
<?
/*
** dactylo.php
** Login : <radeff@radeff-desktop>
** Started on  Wed Nov 19 20:50:07 2008 Fred Radeff
** $Id$
** 
** Copyright (C) 2008 Fred Radeff
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
** 
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

$path="ergolang/"; //wiki
$path=""; //wiki

?>


<script language="JavaScript">

//timer
debut_visite = new Date();
function debut()
{ debut_visite = new Date();
//ici on initialise le temps ecoule
t = 0;
}

//decompte temps ecoule
//NE MARCHE QUE SI ON SORT DE LA CARTE...
//IL Y A UN BUG - CALCULE TROP VITE...
function tempsEcoule(){
comptage = setInterval("t++", 1000);
tMin= Math.floor(t / 60);
  tSec = t % 60;
defaultStatus = 'Vous survolez la carte depuis... ' +tMin +' minutes ' +tSec +' secondes';
}

function fin()
{ fin_visite = new Date();
  duree = Math.round((fin_visite - debut_visite) / 1000);
  duree_minutes = Math.floor(duree / 60);
  duree_secondes = duree % 60;
  alert("Vous avez survole la carte pendant... " + 
        (duree_minutes == 0 ? "" : (duree_minutes + " mn et "))
        + duree_secondes + " s.");
}

<?
echo "
function change(x){
var y=document.getElementById(x).value;
y=y.toLowerCase(); //on met en minuscule pour la comparaison
yLong=y.length;
document.getElementById(x).value=y;
lebonmot=\"" .$goodwordForeign ."\";
lebonmot=lebonmot.toLowerCase(); //on met en minuscule pour la comparaison
lebonmotCourt=lebonmot.substring(0,yLong);
alert(lebonmotCourt);
";
?>
  if(y==lebonmot) { //match
alert('bravo!');
//alert('bravo, <a href="http://www.akademia.ch/websites/<? echo $path; ?>wiki/doku.php?do=show&id=russe%3Avocversiontapetrad">new question</a>');
//bug!
/*window.document.location.href='http://www.akademia.ch/websites/<? echo $path; ?>wiki/doku.php?do=show&id=russe%3Avocversiontapetrad';*/
//document.write('<meta http-equiv="refresh" content="1;URL=http://www.akademia.ch/websites/<? echo $path; ?>wiki/doku.php?do=show&id=russe%3Avocversiontapetrad">');
 } else if(y==lebonmotCourt){ //begin match
 document.getElementById("traduction").style.borderColor = "#0000ff";
  document.getElementById("traduction").style.backgroundColor = "#a7ff7c";
  document.getElementById("traduction").style.color = "#000000";

 } else { //wrong
  document.getElementById("traduction").style.borderColor = "#0000ff";
  document.getElementById("traduction").style.backgroundColor = "#ff8b8b";
  document.getElementById("traduction").style.color = "#000000";
/* si faux efface dernier caractere: ne marche pas, ce serait bien de trouver le bug
ylong=(ylong-1);
document.getElementById(x).value=y.substring(0,ylong);
*/
 }

}
</script>
<!--   <body onLoad="debut();PlaceCalque(0)" onUnload=fin()>-->
<body onLoad="PlaceCalque(0)">
<?
include("clavier.inc.php");
?>

<?
/* ici on cherche a savoir ce que l'on tape et a comparer le d�but du string avec celui de la traduction du mot propos� */
/* note Fred: attention au m�lange js, php et html; ne pas rouvrir de balises php - il perd les variables, donc tout ecrire en php, y compris le js et le html */

$utilisateur= $_SESSION[DOKU_COOKIE]['auth']['user'];
echo "Welcome, " .$utilisateur;
include($path ."config.inc.php");
include($path ."fonctions.inc.php"); 
include($path ."header.head.inc.php"); 
//echo "<br>Login db: " .$login; echo "<br>"; echo $pass; //tests to see if var correctely included
$db=mysql_connect("localhost",$login,$pass) or  die("Unable  to  select  database");
mysql_select_db($database_name,$db);
mysql_query("SET NAMES 'utf8'");
$latable="ergo_rufrs"; //initializing vocabulary table
$question="SELECT * FROM " .$latable;
$question=mysql_query($question); //finding all words

if(!$question){
	echo "Error mysql: " .mysql_error();
}
$questionN=mysql_num_rows($question); //the number of words

#echo "question: " .$questionOri ." - # " .$questionN ."<hr>"; //tests 

$i=0;

#$goodword=rand(0,$questionN); //creating random number 1 = good word
$goodword=$rand->uRand(1,$questionN); //creating random number 1 = good word

#echo "test; langue = " .$langue ."<br>SQL: " .$questionOri ."<br>urand: " .$goodword;

$goodwordForeign=mysql_result($question,$goodword,'foreign');
$goodwordLocal=mysql_result($question,$goodword,'local');

/* Some JS BEGIN */
echo "

";
/* Some JS END */

echo "
<!-- print game -->
<!-- put some js here -->
<form>
<input type=\"hidden\" name=\"utilisateur\" value=\"".$utilisateur ."\">
<input type=\"hidden\" name=\"langue\" value=\"".$langue ."\">
<input type=\"hidden\" name=\"goodwordForeign\" value=\"" .$goodwordForeign ."\">
<table>
<tr><th colspan=\"3\">Tapez: <b>".$goodwordForeign;

#echo " - answer for Test purpose: " .$goodwordLocal;
?>



<?
echo "</b></th></tr><tr>
<td><input type=\"text\" name=\"traduction\" id=\"traduction\" onkeyup=\"change(this.id)\"></td>
 </tr>
</table>
<!--<input type=\"submit\" name=\"action\" value=\"OK, on continue avec un nouveau mot!\">-->
<input type=\"submit\" name=\"action\" value=\"J'abandonne, nouveau mot!\">
</form>
";


?>
